home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / pwrclib.exe / REPCHAR.C < prev    next >
Text File  |  1992-09-01  |  640b  |  28 lines

  1. /* repchar function Copyright 1992 by Chuck Steenburgh
  2.  
  3.    This function will replace all instances of a given character
  4.    in a string with another
  5.    
  6.    repchar accepts the following arguments:
  7.    
  8.    char *s - string in which character(s) are to be replaced
  9.    char c  - character to be replaced
  10.    char r  - replacement character
  11.    
  12.    Returns:  number of character replaced
  13.                                                                          */
  14.  
  15. int repchar(char *s, char c, char r)
  16.     
  17. {
  18.     /* local variable */
  19.     int counter=0;
  20.     
  21.     while (s = strchr(s,c)) {
  22.         *s = r;
  23.         counter++;
  24.     }
  25.     
  26.     return counter;
  27. }
  28.